//
//  ImageTextResponse.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/24.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "ImageTextResponse.h"
#import "Masonry.h"
#import "CellOfFirst.h"
#import "FlowlayoutOfImageText.h"
#import "NetWorkingHandle.h"
#import "VCOfUser.h"
#import "VCOfTools.h"
#import "ImageTextModle.h"
#import "ModelOfTuwen.h"

@interface ImageTextResponse ()

@property(nonatomic, retain)NSMutableArray *arrOfStep;


@end

@implementation ImageTextResponse

//static NSString * const reuseIdentifier = @"Cell";


- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
                                       Model:(ImageTextModle *)model
{
    if (self = [super initWithCollectionViewLayout:layout])
    {
        self.strOfhandId = model.hand_id;
        NSLog(@"%@", self.strOfhandId);
    }
    
    return self;
}


- (void)dealloc{
    [_arrOfStep release];
    [_strOfhandId release];
    [super dealloc];
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    self.collectionView.backgroundColor = [UIColor clearColor];
    [self.collectionView registerClass:[CellOfFirst class] forCellWithReuseIdentifier:@"pool1"];
//    self.collectionView.backgroundColor = [UIColor yellowColor];
    
          
    [self GetData];
    [self collectionViewConfig];
    
    
   
}

- (void)GetData{
    
    NetWorkingHandle *net = [[NetWorkingHandle alloc]init];
    
    self.arrOfStep = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat: @"http://m.shougongke.com/index.php?&c=Course&a=CourseDetial&id=%@&vid=18", self.strOfhandId];
    
    [net netWorkingHandlerGetWithURL:url completion:^(id result, NSData *data, NSURLResponse *response, NSError *error)
    {
        NSArray *arr = [[result objectForKey:@"data"]objectForKey:@"step"];
        for (NSDictionary *dic in arr)
        {
            ModelOfTuwen *model = [[ModelOfTuwen alloc]init];
            
            [model setValuesForKeysWithDictionary:dic];
            [self.arrOfStep addObject:model];
        }
        
        NSLog(@"1111%ld", self.arrOfStep.count);
        
        [self.collectionView reloadData];
    }];
    
    
    
    
}


- (void)collectionViewConfig{
    
    VCOfUser *uservc = [[VCOfUser alloc]init];
    uservc.strOfhand_id = self.strOfhandId;
    VCOfTools *toolsvc = [[VCOfTools alloc]init];
    toolsvc.strOfId = self.strOfhandId;
    
    [self.collectionView addSubview:uservc.view];
    
    [uservc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.collectionView.mas_centerX);
        make.centerY.equalTo(self.collectionView.mas_centerY);
        make.height.equalTo(self.collectionView.mas_height);
        make.width.equalTo(self.collectionView.mas_width);
    }];
    
    
   [self.collectionView addSubview:toolsvc.view];
    [toolsvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(uservc.view.mas_top).offset(0);
        make.leading.equalTo(uservc.view.mas_trailing).offset(0);
        make.height.equalTo(uservc.view.mas_height);
        make.width.equalTo(uservc.view.mas_width);
    }];
    
    
    [self addChildViewController:uservc];
    [self addChildViewController:toolsvc];
    
    [toolsvc release];
    [uservc release];
    
    
    
    
    
    
    
}





#pragma mark <UICollectionViewDataSource>




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return  self.arrOfStep.count + 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CellOfFirst *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool1" forIndexPath:indexPath];
    if (indexPath.row > 1)
    {
        
        cell.model = self.arrOfStep[indexPath.item - 2];
        
        return cell;
    }
    else
    {
        
//        cell.imageOfBig.backgroundColor = [UIColor colorWithRed:248.0 / 256.0f green:239.0 / 256.0f blue:239.0 / 256.0f alpha:1];
        
        return cell;
    }
   
    
    
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
